<?php
function updateimg($date, $filename,$path='')
{

    if (!empty($_SERVER['HTTP_APPNAME'])) {
        $weburl = saeup($date, $filename,$path);
    } else {
        $weburl = commenup($date, $filename,$path);
    }
    return $weburl;
}

function commenup($date, $filename,$path='')
{   

    

    $folder=$path==''?'/data/images/':$path;
    $path = dirname(__FILE__) . "/..".$folder;
    //允许上传的文件格式
    $tp = array("image/pjpeg", "image/jpeg", "image/png");
    //检查上传文件是否在允许上传的类型
    if (!in_array($date["type"], $tp)) {
        echo "不能上传该文件格式";
        exit;
    }//END IF


    if ($date["name"]) {

        $file_name = $date["name"];

        $info = pathinfo($file_name);
        //给扩展名赋值
        $etc = $info['extension'];
        $file1 = $filename . '.' . $etc;

        var_dump($file1);
        // exit();
        
        //文件名称 取原文件名
        $file2 = $path . $file1;
    }
    $result = move_uploaded_file($date["tmp_name"], $file2);
    return Web_ROOT . $folder . $file1;
}

function saeup($date, $filename)
{   
    // echo 22; 
    // exit();
    $storage = new SaeStorage();
    $domain = 'img';
    $destFileName = $filename . 'jpg';
    $srcFileName = $_FILES['tmp_name'];
    $result = $storage->upload($domain, $destFileName, $date["tmp_name"]);
    return $result;
}